<template>
    <view>
        <view>
            <uni-search-bar placeholder="海量好房，一键搜索！" @confirm="search()" v-model="searchValue">
                <uni-icons slot="searchIcon" color="#999999" size="18" type="home" />
            </uni-search-bar>
        </view>
        <view>
            
        </view>
        <view>
            <view class="uni-flex uni-row" v-for="(i,index) in rent" :key="index">
				<rentinglist v-bind:rent="i"></rentinglist>
            </view>
        </view>
    </view>
</template>

<script>
    import {UniSearchBar} from "@dcloudio/uni-ui"
    // import HMfilterDropdown from '@/components/HM-filterDropdown/ffff.vue';
    import rentinglist from "./rentinglist.vue"
    export default {
        name: "house_rent_in",
        data(){
            return{
                searchValue:'',
                rent:[]
            }
        },
        methods:{
            search(){
            },
            getHouse(){
                this.$axios.post('getAllHouses')
                .then(res =>{
					this.house = res.data.allHouses
					this.getSell()
					this.$forceUpdate()
                })
            },
			getHousebyMap(add){
				let data = {address:add}
				this.$axios.post('getHousesByMap',this.qs.stringify(data))
				.then(res =>{
					// console.log(res.data.allHouses);
					this.house = res.data.allHouses;
					this.getSell()
					this.$forceUpdate();
				})
			},
            getSell(){
                this.$axios.post('getAllRentings')
                .then(res =>{
                    this.rentingHouse = res.data.allRentings
                    for(let j=0 ; j < this.house.length ; j++){
                        for(let k=0 ; k < this.rentingHouse.length ; k++){
                            if(this.rentingHouse[k].houseId == this.house[j].houseId){
                                let temporary = {}
                                temporary.houseId = this.rentingHouse[k].houseId
                                temporary.rentingHeading = this.rentingHouse[k].rentingHeading
                                temporary.rentingPrice = this.rentingHouse[k].rentingPrice
                                temporary.houseEstate = this.house[j].houseEstate
                                temporary.houseArea = this.house[j].houseArea
                                temporary.houseSurfaceplot = this.house[j].houseSurfaceplot
                                temporary.houseDirection = this.house[j].houseDirection
                                temporary.houseRegion = this.house[j].houseRegion
                                temporary.houseCity = this.house[j].houseCity
                                this.rent.push(temporary)
                            }
                        } 
					}
					this.rent.reverse()
                })
                this.$forceUpdate()
            }
        },
        onLoad(option) {
			let data = option;
			if(data.lon == undefined){				
				this.getHouse()
			}
			else{
				console.log('house_buy')
				console.log(data)		
				var params = {};
				
				let that = this;
				uni.request({
					url: 'https://restapi.amap.com/v3/geocode/regeo', //仅为示例，并非真实接口地址。
					data: {//参数
							location: data.lon+','+data.lat,
							key: 'c57eab66ecef610118acf5f0e13c1d82'
						},
					method:'GET',//请求方式  或GET，必须为大写
					success: res => {
						console.log('返回', res.data);
						let compo = res.data.regeocode.addressComponent;
						let str = compo.province.toString() + compo.city.toString()+
						compo.district.toString()+compo.township.toString();
						console.log(str);		
						that.getHousebyMap(str)
						that.getSell()
						that.$forceUpdate()
					}
					})
			}
        },
        components:{
            UniSearchBar,
            rentinglist
        }
    }
</script>

<style scoped>

</style>
